
import { Header } from '../components/header/';
import { Carousel } from '../components/carousel/';
import { ShowBoard } from '../components/show_board/';
import { BoardTitle } from '../components/board_title';
import { Footer } from '../components/footer/'
import { App } from './App.js';


class Index extends App{
    constructor($){
       super($,{
           swiper:true,
           phone:true,
           field:true
       })
    }
     render(){
      
        new Header(this.$app,this.cache.fieldDatas,this.cache.phoneDatas).init();
        new Carousel(this.$app,this.cache.swiperDatas).init();
        new BoardTitle(this.$app,"手机上新").init();
        new ShowBoard(this.$app,this.filterData('new')).init();
        new BoardTitle(this.$app,"超值手机").init();
        new ShowBoard(this.$app,this.filterData('most_value')).init();
        new BoardTitle(this.$app,"官方推荐").init();
        new ShowBoard(this.$app,this.filterData('recom')).init();
        new Footer(this.$app).init();
        
        $('body').prepend(this.$app);

    }
   filterData(field){
     return this.cache.phoneDatas.filter((item,idx)=>{
           switch(field){
               case 'new':
                  return item.new == 1;
                  break;
                case 'recom':
                    return item.recom == 1;
                    break;
                case 'most_value':
                    return item.most_value == 1;
                    break;
                default:
                    break;
               }
           });
   }

}
new Index(jQuery);